package renguanyu.app.tools.util;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class SeleniumUtil {

	static {
		System.setProperty("webdriver.chrome.driver", getChromeDriverPath());
	}

	public static WebDriver getWebDriver() {
		ChromeOptions options = new ChromeOptions();
		options.setBinary(getChromeBinPath());
		options.addArguments("--remote-allow-origins=*");
		options.addArguments("--start-maximized");
		options.addArguments("disable-infobars");
		WebDriver webDriver = new ChromeDriver(options);
		// webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
		return webDriver;
	}

	public static void quitWebDriver(WebDriver webDriver) {
		if (webDriver != null) {
			webDriver.quit();
		}
	}

	private static String getChromeBinPath() {
		String result = "./chrome/129.0.6668.58/chrome-win64/chrome.exe";
		if (SystemUtil.isDevEnv()) {
			return result.replace("./", "./data/");
		}
		return result;
	}

	private static String getChromeDriverPath() {
		String result = "./chrome/129.0.6668.58/chromedriver-win64/chromedriver.exe";
		if (SystemUtil.isDevEnv()) {
			return result.replace("./", "./data/");
		}
		return result;
	}

}
